package com.example.demo.service.impl;

import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.example.demo.mapper.UserMapper;
import com.example.demo.pojo.Page;
import com.example.demo.pojo.User;
import com.example.demo.service.UserService;

@Service
public class  UserServiceImp implements UserService {
    
    @Autowired
    UserMapper userMapper;

    @Override
    public void insert(User user) {
        userMapper.insert(user);
    }
    

    @Override
    public void updateUser(User user) {
        userMapper.update(user);
    }

    @Override
    public void deleteUser(Integer id) {
        userMapper.delete(id);
    }
    @Override
    public void deleteBatchUser(List<Integer> ids) {
        for(Integer id : ids){
            userMapper.delete(id);
        }
    }

    @Override
    public  List<User> selectAll() {
        return userMapper.selectAll();
    }
    
    @Override
    public User selectById(Integer id) {
        return userMapper.selectById(id);
    }
    @Override
    public List<User> selectByName(String name) {
        return userMapper.selectByName(name);
    }
    @Override
    public List<User> selectByMore(String username, String name) {
        return userMapper.selectByMore(username, name);
    }

    @Override
    public List<User> selectByLike(String username, String name) {
        return userMapper.selectByLike(username, name);
    }

    @Override
    public Page selectByPage(Integer pageNum, Integer pageSize, String username, String name) {
        Page<User> page = new Page<>();

        Integer skipNum = (pageNum - 1) * pageSize;
        List<User>  userlist = userMapper.selectByPage(skipNum, pageSize, username, name);
        int total = userMapper.selectCount(username, name);
        page.setTotal(total);
        page.setList(userlist);
        return page;
    }
}
